package com.sky.service.impl;

import com.sky.constant.MessageConstant;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.WorkerDTO;
import com.sky.dto.WorkerLoginDTO;
import com.sky.entity.Employee;
import com.sky.entity.Worker;
import com.sky.exception.AccountNotFoundException;
import com.sky.mapper.EmployeeMapper;
import com.sky.mapper.WorkerMapper;
import com.sky.service.WorkerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WorkerServiceImp implements WorkerService {


    @Autowired
    private WorkerMapper workerMapper;
    //工人端用户登录。
    public Worker login(WorkerLoginDTO workerLoginDTO){
        String name = workerLoginDTO.getName();
        String workid = workerLoginDTO.getWorkid();

        Worker Workerid = workerMapper.getByWorkerid(workerLoginDTO.getWorkid());

        if ( Workerid == null) {
            //账号不存在
            throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND);
        }
        return Workerid;
    }

    @Override
    public void update(WorkerDTO workerDTO) {
        Worker worker=new Worker();
        BeanUtils.copyProperties(workerDTO,worker);
        workerMapper.update(worker);
    }




}
